<template>
    <div>
        <el-tree :props="props" :load="loadNode" lazy @node-click="nodeClick"></el-tree>
    </div>
</template>

<script>
export default {
    data() {
        return {
            props: {
                label: 'name',
                children: 'zones',
                isLeaf: 'leaf'
            },
        };
    },
    methods: {
        loadNode(node, resolve) {
            if (node.level === 0) {
                // //发请求拿第一级的数据
                // if(res.code === 1){
                //     return resolve(res.data);
                // }
                return resolve([{ name: 'region1' },{ name: 'region2' },{ name: 'region3' }]);
            }
            if (node.level >= 1) {
                // //发请求拿第多级的数据
                // //这里根据后端返回的cid判断是二级还是三级，发请求带一个cid
                // if(res.code === 1){
                //     return resolve(res.data);
                // }else{
                //     return resolve([]);
                // }
                return resolve([{ name: 'region11' },{ name: 'region22' },{ name: 'region33' }]);
            }
        },
        nodeClick(data){
            //传递给父组件数据渲染
            this.$emit('sendTree',data)
        }
    }
};
</script>

<style scoped lang="less"></style>
